package leetcode;
/**
 * The rand7() API is already defined in the parent class SolBase.
 * public int rand7();
 * @return a random integer in the range 1 to 7
 */

public class Leetcode470 {
    public int rand10() {
        while(true){
            //random7
            int num = (rand7()-1)*7+rand7();
            if(num<=40){
                return num%10+1;
            }
            //random9
            num = (num-40-1)*7+rand7();
            if(num<=60){
                return  num%10+1;
            }
            //random3
            num = (num-60-1)*7+rand7();
            if(num<=20){
                return  num%10+1;
            }
        }
    }

    public int rand7(){
        return (int)Math.random()%7;
    }
}
